import Router from 'vue-router'
import Login from './login.vue'
import Home from './home.vue'
import Title from './components/titleBar.vue'
import Detail from './project/detail.vue'
import BackBar from './components/backBar.vue'
import Serve from './serve/index.vue'
import { Auth } from './http'
Vue.use(Router);

const routes = [
  { path: '/', redirect: '/login' },
  { path: '/login', components: {default:Login} },
  { path: '/home', components: {default:Home, title: Title} },
  { path: '/serve', components: {default:Serve, title: BackBar}, props: {title: '技术支持'} },
  { path: '/detail/:id', components: {default:Detail, title: BackBar}, props: {title: '项目详情'} },
  { path: '/logout', beforeEnter: Auth.logout }
];

const router = new Router({
  routes,
});
const permissive = ['/login', '/logout']
router.beforeEach((to, from, next) => {
  if (permissive.includes(to.path) || Auth.isLogin()) {
    console.log(Auth.isLogin())
    return next()
  }
  next({
    path: '/login',
    query: {redirect: to.path}
  })
});
export default router